package com.deep.nacos.controller;

import com.deep.nacos.config.MyDynamicThreadPool;
import com.deep.nacos.entity.MyRunnable;
import com.dtp.core.DtpRegistry;
import com.dtp.core.thread.DtpExecutor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.concurrent.ThreadPoolExecutor;

@RestController
@RequestMapping("/test")
public class TestController {

    @Resource
    private MyDynamicThreadPool dynamicThreadPool;

    @Resource
    private ThreadPoolExecutor dtpExecutor1;


    @RequestMapping("/execute")
    public String execute() {
        dynamicThreadPool.execute(new MyRunnable());
        dynamicThreadPool.print();

        return "done";
    }

    @RequestMapping("/test1")
    public String test1() {

        dtpExecutor1.execute(() -> System.out.println("test"));
        return "done";

    }

    @RequestMapping("/test2")
    public String test2() {

        DtpExecutor dtpExecutor = DtpRegistry.getDtpExecutor("dtpExecutor1");
        dtpExecutor.execute(() -> System.out.println("test"));
        return "done";

    }
}